#include <QMessageBox>
#include "PreviewCapture.h"
#include "ui_PreviewCapture.h"

PreviewCapture::PreviewCapture(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::PreviewCapture)
{
	ui->setupUi(this);

	connect(ui->btnCancel, SIGNAL(clicked()), SLOT(SlotCancel()));
	connect(ui->btnSave, SIGNAL(clicked()), SLOT(SlotSave()));
}

PreviewCapture::~PreviewCapture()
{
	delete ui;
}

void PreviewCapture::setPreview(QString &strFilepath)
{
	ui->imagePreview->setImagePath(strFilepath);
}

void PreviewCapture::SlotCancel()
{
	QMessageBox msg(this);

	msg.setText("저장 취소 여부 확인");
	msg.setInformativeText("저장을 취소하시겠습니까?");
	msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
	msg.setDefaultButton(QMessageBox::No);
	msg.setEscapeButton(QMessageBox::No);
	msg.setButtonText(QMessageBox::Yes, "확인");
	msg.setButtonText(QMessageBox::No, "아니오");

	int iResult = msg.exec();

	switch (iResult)
	{
	case QMessageBox::Yes:
		this->PromptCaptureMore();
		break;
	default: //No
		break;
	}
}

void PreviewCapture::SlotSave()
{
	this->RequestSaveCapture();
	this->PromptCaptureMore();
}

void PreviewCapture::RequestSaveCapture()
{
	emit SignalNewCapture();
}

void PreviewCapture::PromptCaptureMore()
{
	QMessageBox msg(this);

	msg.setText("재촬영 여부 확인");
	msg.setInformativeText("재촬영 하시겠습니까?\n아니면 종료하시겠습니까?");
	msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
	msg.setDefaultButton(QMessageBox::No);
	msg.setEscapeButton(QMessageBox::No);
	msg.setButtonText(QMessageBox::Yes, "재촬영");
	msg.setButtonText(QMessageBox::No, "종료");

	if(msg.exec() == QMessageBox::Yes) emit SignalCaptureMore();
	else emit SignalCaptureProcessEnd();
}
